﻿/* **************************************************************************
 * ITEMS
 * **************************************************************************
 * Written by: Coppra Games
 * Created: June 2017
 * *************************************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Items : MonoBehaviour {

	public static Dictionary<int, ItemsCollection.ItemData> items;
	// public static Dictionary<int, ItemsCollection.ModelData> models;


	public static void LoadItems()
	{
		items = new Dictionary<int, ItemsCollection.ItemData>();

		ItemsCollection itemsCollection = Resources.Load("ItemsCollection", typeof(ItemsCollection)) as ItemsCollection;
		if (itemsCollection != null)
		{
			for (int index = 0; index < itemsCollection.list.Count; index++)
			{
				ItemsCollection.ItemData itemData = itemsCollection.list[index];
				items.Add(itemData.id, itemData);
			}
		}
		else
		{
			Debug.LogError("ItemsCollection is missing! please go to 'Windows/Item Editor'");
		}
	}
	// public static void LoadModels()
	// {
	// 	models = new Dictionary<int, ItemsCollection.ModelData>();
	// 	ItemsCollection itemsCollection = Resources.Load("ItemsCollection", typeof(ItemsCollection)) as ItemsCollection;
	// 	if (itemsCollection != null)
	// 	{
	// 		for (int index = 0; index < itemsCollection.list.Count; index++)
	// 		{
	// 			ItemsCollection.ModelData itemData = itemsCollection.modelList[index];
	// 			models.Add(itemData.id, itemData);
	// 		}
	// 	}
	// 	else
	// 	{
	// 		Debug.LogError("ItemsCollection is missing! please go to 'Windows/Item Editor'");
	// 	}
	// }
		
	public static ItemsCollection.ItemData GetItem(int itemId)
	{
		ItemsCollection.ItemData item = null;
		if (!items.TryGetValue(itemId, out item))
		{
			Debug.LogWarning(string.Format("itemid: {0} is not exit", itemId));
		}
		return item;
	}
	public static List<ItemsCollection.ItemData> GetAllItem()
	{
		List<ItemsCollection.ItemData> list = new List<ItemsCollection.ItemData>();
        foreach (var item in items)
        {
            list.Add(item.Value);
        }
        return list;
	}
	// public static ItemsCollection.ModelData GetModel(int itemId)
	// {
	// 	ItemsCollection.ModelData item = null;
	// 	models.TryGetValue(itemId, out item);
	// 	return item;
	// }
}
